<?php
    require_once('popup_base_jectly.php');

	/*
     * sub classes of page_base_jectly will include only the changes from index_2;
	 */
	class popup_report_violation extends popup_base_jectly {

        protected $contents_html='<div class=\'center\'>This is popup_report_violation page.</div>';

        protected $id;//project_id
        public $project;
        protected $uid;//target_user's user_id(violation user)
        public $target_user;

        function __construct() {
            parent::__construct();
        }

        protected function Form_Create() {

            $this->check_query_string();

            $this->load_project();
            
            $this->load_target_user();
		}

        protected function check_query_string()
        {
            if(is_numeric(QApplication::QueryString('id')))
            {
                $this->id=QApplication::QueryString('id');//project_id
            }

            if(is_numeric(QApplication::QueryString('uid')))
            {
                $this->uid=QApplication::QueryString('uid');//provider_id
            }
        }

        protected function load_project()
        {
            if(isset($this->id) && is_numeric($this->id))
            {
                $this->project=TableProject::LoadById($this->id);

                if(isset($this->project))
                {
                    $this->contents_html='project loaded-['.$this->project->Title.'] user_id=['.$this->project->UserId.']';
                }
                else
                {
                    $this->contents_html='project not found id=['.$this->id.']';
                    $this->id=null;
                    $this->project=null;
                }
            }
        }

        protected function load_target_user()
        {
            if(isset($this->uid) && is_numeric($this->uid))
            {
                $this->target_user=TableUserProject::LoadById($this->uid);

                if(isset($this->provider))
                {
                    $this->contents_html.=' target_user loaded-['.$this->target_user->UserName.'] user_id=['.$this->target_user->UserId.']';
                }
                else
                {
                    $this->contents_html.=' target_user not found id=['.$this->uid.']';
                    $this->uid=null;
                    $this->target_user=null;
                }
            }
        }

        //check permissions
        public function bool_target_user_loaded()
        {
            return isset($this->target_user);
        }

        //check permissions
        public function bool_project_loaded()
        {
            return isset($this->project);
        }

        public function bool_my_project()
        {
            if(isset($this->project) && isset($this->UserId))
            {
                return $this->project->bool_my_project($this->UserId);
            }

            return false;
        }

        public function bool_won_project()
        {
            if(isset($this->project) && isset($this->UserId))
            {
                return $this->project->bool_won_project($this->UserId);
            }

            return false;
        }

        public function bool_project_open()
        {
            if(isset($this->project) && isset($this->UserId))
            {
                return $this->project->bool_open_project();
            }

            return false;
        }

        public function bool_project_after_picked()
        {
            if(isset($this->project) && isset($this->UserId))
            {
                return $this->project->bool_after_picked_project();
            }

            return false;
        }

        public function bool_project_bidding_end()
        {
            if(!bool_project_open() && !bool_project_after_picked())return true;

            return false;
        }

        public function bool_report_violation_permitted()
        {
            if(!$this->bool_logined())return false;

            return false;
        }

        public function render_contents_area() {

            if($this->bool_contents_area_on)
            {
                echo($this->contents_html);
            }
        }

	}

    popup_report_violation::Run('popup_report_violation','popup_report_violation.tpl.php');

?>